


//
//  YZQ24HourSecondTableViewCell.m
//  SuperNews
//
//  Created by qiang on 16/1/13.
//  Copyright © 2016年 qiang. All rights reserved.
//

#import "YZQ24HourSecondTableViewCell.h"

@implementation YZQ24HourSecondTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubView];
    }
    return self;
    
}

- (void)createSubView {
    
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 90 * SMALLSCREEN_WIDTH, 75)];
    
    [self.contentView addSubview:self.headImageView];
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.frame = CGRectMake(110, 10, 250, 30);
    
    [self.contentView addSubview:self.titleLabel];
    
    self.describeLabel = [[UILabel alloc] initWithFrame:CGRectMake(110 * SMALLSCREEN_WIDTH, 50, 250 * SMALLSCREEN_WIDTH, 40)];
    self.describeLabel.font = [UIFont systemFontOfSize:14.0];
    self.describeLabel.textColor = [UIColor lightGrayColor];
    self.describeLabel.numberOfLines = 0;
    
    [self.contentView addSubview:self.describeLabel];
    
    // 将UITextField当做label来用,因为UITextField可以设置圆角,将它的用户交互关闭
    self.followUpLabel = [[UITextField alloc] initWithFrame:CGRectMake(300 * SMALLSCREEN_WIDTH , 75, 70 * SMALLSCREEN_WIDTH , 15)];
    self.followUpLabel.center = CGPointMake(330 * SMALLSCREEN_WIDTH, 82.5);
    // 设置文字的对齐方式
    self.followUpLabel.textAlignment = NSTextAlignmentCenter;
    self.followUpLabel.font = [UIFont systemFontOfSize:11.0];
    self.followUpLabel.borderStyle = UITextBorderStyleRoundedRect;
    self.followUpLabel.userInteractionEnabled = NO;
    self.followUpLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.followUpLabel];
    
    self.numImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vote_multi_tag@2x.png"]];
    self.numImageV.frame = CGRectMake(10, 70, 20 * SMALLSCREEN_WIDTH, 15);
    [self.contentView addSubview:self.numImageV];
    
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 20 * SMALLSCREEN_WIDTH, 15)];
    [self.contentView addSubview:self.numLabel];
    
    
}

- (void)setModel:(NewsPageModel *)model
{
    _model = model;
    self.titleLabel.text = self.model.title;
    self.describeLabel.text = self.model.digest;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.model.imgsrc] placeholderImage:nil];
    
    CGFloat replayC = [self.model.replyCount floatValue];
    if (replayC > 0) {
        NSString *replayStr = [NSString stringWithFormat:@"%.0f跟帖", replayC];
        if (replayC >= 10000 ) {
            replayStr = [NSString stringWithFormat:@"%.1f万跟帖", replayC / 10000];
        }
        NSInteger lenth = replayStr.length;
        CGFloat w = (lenth + 2) * 8.0 + 5;
        CGRect temp = self.followUpLabel.frame;
        temp.size.width = w;
        self.followUpLabel.frame = temp;
        self.followUpLabel.center = CGPointMake(330, 82.5);
        self.followUpLabel.text = replayStr;
    }else
    {
        self.followUpLabel.borderStyle = UITextBorderStyleNone;
    }
    
}


@end
